// 1. 导入mongoose
const mog = require('mongoose');
// 2. 连接数据库
mog.connect('mongodb://localhost/1208')
// 3. 创建连接回调 connection.on("open",callback)
mog.connection.on('open',()=>{
    console.log("连接成功");
})
mog.connection.on('error',()=>{
    console.log("连接失败");
})
    // 5. 创建文档解构 new mongoose.Schema()
let songSchema = new mog.Schema({
    name:String,
    singer:String,
    price:Number
})
    // 6. 创建模型对象 mongoose.model()
let songModel = mog.model('songs',songSchema);
    // 7. 单条删除 model.deleteOne({},callback)

// songModel.deleteOne({name:"发如雪"},(err,data)=>{
//     if(err) return;
//     console.log(data);
// });

    // 8. 批量删除 model.deleteMany({}.callback)
songModel.deleteMany({singer:"周杰伦"},(err,data)=>{
    if(err){
        console.log(err);
        return;
    } 

    console.log(data);
})